package com.qc31.monitorlib.ui.line

import android.view.View
import android.widget.ImageView
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.qc31.baselib.base.LazyFragment
import com.qc31.baselib.databinding.IncludeRecyclerMathMBinding
import com.qc31.baselib.utils.loadGif
import com.qc31.comlib.entity.HistoryLine
import com.qc31.monitorlib.R
import com.qc31.monitorlib.ui.adapter.DataAdapter


/** @Author Jasper @Time 2020/8/12 @Desc 历史轨迹--报警 */
class AlarmLineFragment :
    LazyFragment<IncludeRecyclerMathMBinding>(IncludeRecyclerMathMBinding::inflate) {

    private val mActivityVM by activityViewModels<LineInfoViewModel>()
    override fun initView(view: View) {
        binding.recyclerView.layoutManager = LinearLayoutManager(context)
    }

    //空布局
    private val emptyView by lazy {
        val view = layoutInflater.inflate(
            R.layout.layout_empty_view,
            binding.recyclerView,
            false
        )
        view.findViewById<ImageView>(R.id.ivNoData).loadGif(requireContext(), R.mipmap.ic_empty)
        view
    }

    override fun initData() {
        mActivityVM.data.observe(this) {
            val dataAdapter = DataAdapter<HistoryLine.AlarmData>(1)
            binding.recyclerView.adapter = dataAdapter
            if (it.alarmData.isNullOrEmpty()) {
                dataAdapter.setEmptyView(emptyView)
                return@observe
            }
            val list: MutableList<HistoryLine.AlarmData> = ArrayList()
            list.addAll(it.alarmData)

            dataAdapter.setList(list)
        }

    }

    override fun initEvent() {

    }
}